from access.core.utterancegenerator import UtteranceGenerator
from access.core.utterancepattern import UtterancePattern
import unittest

class UtteranceGeneratorTest(unittest.TestCase):
  def testGenerateFromPatternWithoutContext(self):
    utterance_pattern = UtterancePattern \
    (value_pattern = 'say something',
     snippet_ID_pattern = 'code something')
    
    generator = UtteranceGenerator()
    infos = generator.Generate(utterance_pattern)
    self.assertEqual(1,
                     len(infos),
                     'Expected one utterance info. Actual: %s' % len(infos))
    self.assertEqual('say something', infos[0].value)
    self.assertEqual('code something', infos[0].snippet_ID)

  def testGenerateFromPattern(self):
    utterance_pattern = UtterancePattern \
    (value_pattern = 'say {{token}}',
     snippet_ID_pattern = 'code using {{token}}',
     token = ['a', 'b'])
    
    generator = UtteranceGenerator()
    infos = generator.Generate(utterance_pattern)
    self.assertEqual(2,
                     len(infos),
                     'Expected one utterance info. Actual: %s' % len(infos))
    self.assertEqual('say a', infos[0].value)
    self.assertEqual('code using a', infos[0].snippet_ID)
    self.assertEqual('say b', infos[1].value)
    self.assertEqual('code using b', infos[1].snippet_ID)
